//
//  YYMusicTool.m
//  音乐播放器
//
//  Created by zpy on 15/11/28.
//  Copyright © 2015年 zpy. All rights reserved.
//

#import "YYMusicTool.h"
#import "YYMusic.h"
#import "MJExtension.h"

@implementation YYMusicTool
static NSArray *_musics;
static YYMusic *_playingMusic;

+(void) initialize {

    _musics = [YYMusic objectArrayWithFilename:@"Musics.plist"];
}
+(NSArray *)musics {

    return _musics;
}
+(YYMusic *)playingMusic {

    return _playingMusic;
}
+(void)setPlayingMusic:(YYMusic *)playingMusic {

    assert(playingMusic);
    _playingMusic = playingMusic;
}
+(YYMusic *)nextMusic {
// 获取当前正在播放的音乐
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    // 获取下一首音乐
    currentIndex ++;
    // 越界处理
    if (currentIndex > _musics.count - 1) {
        currentIndex = 0;
    }
    // 取出下一首音乐
    YYMusic *nextMusic = _musics[currentIndex];
    _playingMusic = nextMusic;
    
    return nextMusic;
}
+(YYMusic *)previousMusic {

    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    currentIndex --;
    if (currentIndex < 0) {
        currentIndex = _musics.count - 1;
    }
    YYMusic *previousMusic = _musics[currentIndex];
    _playingMusic = previousMusic;
    return previousMusic;
}
@end
